using System.Collections.Generic;
using FPLibrary;
using UnityEditor;
using UnityEngine;

namespace PathX.Unity
{

    [DisallowMultipleComponent]
    public partial class PathGridManager : SingleInstanceComponent<PathGridManager>, IPathGridManager
    {
        [SerializeField]
        private PathMode _pathMode;

        private IPathGridManager _manager;
        
        private List<IGrid> _grids = new List<IGrid>(5);
        
        public static PathGridManager Instance { get; private set; }

        public void LoadGrid(IGrid grid)
        {
            _grids.Add(grid);
        }

        public IGrid GetGrid(FPVector pos)
        {
            return _manager.GetGrid(pos);
        }

        public Cell GetCell(FPVector pos)
        {
            return _manager.GetCell(pos);
        }

        protected override void OnAwake()
        {
            Instance = this;
            switch (_pathMode)
            {
                case PathMode.runtime:
                    _manager = new RuntimePathGridManager();
                    break;
                case PathMode.editor:
                    default:
                    _manager = new EditorPathGridManager(this.gameObject);
                    break;
            }
        }
    }
}